package com.kws.tool.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kws.common.core.domain.R;
import com.kws.common.log.annotation.Log;
import com.kws.common.log.enums.BusinessType;
import com.kws.tool.dto.CreateNormManagementRq;
import com.kws.tool.dto.QueryNormManagementRq;
import com.kws.tool.dto.UpdateNormManagementRq;
import com.kws.tool.entity.TbNormManagement;
import com.kws.tool.service.NormManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <b>NormManagementController</b>
 *
 * @description: NormManagementController <br>
 * @date: 2024/11/20 19:20 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Api(tags = "规范维护模块")
@RestController
public class NormManagementController {
    private static final Logger logger = LoggerFactory.getLogger(NormManagementController.class);

    @Autowired
    private NormManagementService normManagementService;

    @ApiOperation("分页查询规范列表")
    @PostMapping("/query/normManagement/page")
    public R<Page<TbNormManagement>> queryNormManagementPage(@RequestBody QueryNormManagementRq rq){
        Page<TbNormManagement> pageInfo = normManagementService.queryNormManagementPage(rq);
        return R.ok(pageInfo);
    }


    @ApiOperation("新增规范信息")
    @Log(title = "新增规范信息", businessType = BusinessType.INSERT)
    @PostMapping("/create/norm")
    public R createNormManagement(@RequestBody CreateNormManagementRq rq){
        boolean status = normManagementService.createNormManagement(rq);
        return R.ok(status);
    }

    @ApiOperation("根据规范ID查询规范详情")
    @GetMapping("/query/normManagement/byId")
    public R<TbNormManagement> queryNormManagementById(@RequestParam Long id){
        TbNormManagement info = normManagementService.queryNormManagementById(id);
        return R.ok(info);
    }

    @ApiOperation("根据规范ID修改规范信息")
    @Log(title = "修改规范信息", businessType = BusinessType.UPDATE)
    @PostMapping("/update/normManagement")
    public R updateNormManagement(@RequestBody UpdateNormManagementRq rq){
        boolean status = normManagementService.updateNormManagement(rq);
        return R.ok(status);
    }

    @ApiOperation("根据规范ID删除规范信息")
    @Log(title = "删除规范信息", businessType = BusinessType.DELETE)
    @GetMapping("/delete/normManagement/byId")
    public R deleteNormManagementById(@RequestParam Long id){
        boolean status = normManagementService.deleteNormManagementById(id);
        return R.ok(status);
    }
}
